<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        var total = 0;

        while (true) {
            var type = prompt('请输入操作方式\n1. 存钱\n2. 取钱\n3. 看余额\n4. 退出');

            // 退出条件
            if (type === '4') {
                break;
            }

            // 错误判断
            if (!(type === '1' || type === '2' || type === '3')) {
                alert('输入有误 请重新输入');
                continue;
            }

            // 需要正常执行
            switch (type) {
                case '1':
                    var save = prompt('请输入存入金额');
                    if (save > 0) {
                        total += Number(save);
                        alert(`余额为【${total}】`);
                    } else {
                        alert('输入有误');
                    }
                    break;
                case '2':
                    var out = prompt('请输入想取出的金额');
                    if (out > 0 && out <= total) {
                        total -= out;
                        alert(`余额为【${total}】`);
                    } else {
                        alert('输入有误');
                    }
                    break;
                case '3':
                    alert(`余额为【${total}】`);
                    break;

                default:
                    break;
            }
        }

    </script>
</body>
</html>